#define _CRT_SECURE_NO_WARNINGS 1

#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>


typedef struct
{
    int* a;
    int front;
    int rear;
    int k;
} MyCircularQueue;

bool myCircularQueueIsEmpty(MyCircularQueue* obj) {
    if (obj->rear == obj->front)
    {
        return true;
    }
    else
    {
        return false;
    }
}

bool myCircularQueueIsFull(MyCircularQueue* obj) {
    if ((obj->rear + 1) % (obj->k + 1) == obj->front)
    {
        return true;
    }
    else
    {
        return false;
    }
}

MyCircularQueue* myCircularQueueCreate(int k) {
    MyCircularQueue* obj = (MyCircularQueue*)malloc(sizeof(MyCircularQueue));
    if (obj == NULL)
    {
        perror("malloc fail");
        return NULL;
    }

    int* tmp = (int*)malloc(sizeof(int) * (k + 1));
    if (tmp == NULL)
    {
        perror("malloc fail");
        return NULL;
    }

    obj->a = tmp;
    obj->front = obj->rear = 0;
    obj->k = k;

    return obj;
}

bool myCircularQueueEnQueue(MyCircularQueue* obj, int value)
{
    if (myCircularQueueIsFull(obj))
    {
        return false;
    }
    else
    {
        obj->a[obj->rear] = value;
        obj->rear = (obj->rear + 1) % (obj->k + 1);
        return true;
    }
}

bool myCircularQueueDeQueue(MyCircularQueue* obj) {
    if (myCircularQueueIsEmpty(obj))
    {
        return false;
    }
    else
    {
        obj->front = (obj->front + 1) % (obj->k + 1);
        return true;
    }
}

int myCircularQueueFront(MyCircularQueue* obj) {
    if (myCircularQueueIsEmpty(obj))
    {
        return -1;
    }
    else
    {
        return obj->a[obj->front];
    }
}

int myCircularQueueRear(MyCircularQueue* obj) {
    if (myCircularQueueIsEmpty(obj))
    {
        return -1;
    }
    else
    {
        obj->rear = (obj->rear + obj->k) % (obj->k + 1);
        return obj->a[obj->rear];
    }
}

void myCircularQueueFree(MyCircularQueue* obj) {
    free(obj->a);
    free(obj);
}

int main()
{
    MyCircularQueue* obj = myCircularQueueCreate(3);
    bool param_1 = myCircularQueueEnQueue(obj, 1);
    bool param_2 = myCircularQueueEnQueue(obj, 2);
    bool param_3 = myCircularQueueEnQueue(obj, 3);
    bool param_4 = myCircularQueueEnQueue(obj, 4);

    int param_5 = myCircularQueueRear(obj);

    bool param_11 = myCircularQueueIsFull(obj);

    bool param_6 = myCircularQueueDeQueue(obj);

    int param_7 = myCircularQueueFront(obj);

    int param_8 = myCircularQueueRear(obj);

    bool param_9 = myCircularQueueIsEmpty(obj);

    bool param_10 = myCircularQueueIsFull(obj);

    myCircularQueueFree(obj);

    return 0;
}